//
//  UserProfile.swift
//  DemoUI
//
//  Created by 白瑾浩 on 2022/4/7.
//

import Foundation
import UIKit
class UserProfile
{
    private var img: UIImage? {
       didSet { /* update ui */ }
    }
    private var bio: String? {
       didSet { /* update ui */ }
    }

    private func loadImage() async -> UIImage? {
        // ...
        sleep( 10 )
        print( "=======loadImage" )
        return nil
    }

    private func loadBio() async -> String? {
        // ...
        
        print( "=======loadBio" )
        return nil
    }

    public func loadData() async {
        
        //顺序执行
//        async let img = loadImage()
//        async let bio = loadBio()
//
//        self.img = await img
//        print( "=======loadData1" )
//        self.bio = await bio
//        print( "=======loadData2" )
        //异步执行
        await withTaskGroup(of: Void.self) { group in
            group.addTask { self.img = await self.loadImage() }
            group.addTask { self.bio = await self.loadBio() }
        }
        
    }
}
